<?php
class CandidatePhotosFForm extends BaseFormAdmin{
	public function configure(){
		$enables = AdminArrayData::getEnabled();
		$this->setWidgets(array(
			'candidate_id'        => new sfWidgetFormDoctrineChoice(array('model' => 'Candidates', 'query' => Doctrine_Query::create()->select('b.id, b.full_name as name')->from('Candidates b')->where('b.is_enabled = 1 AND b.is_deleted = 0 AND (b.updated_at IS NULL OR b.updated_at >= b.created_at)')->orderBy('name asc'),'multiple' => false, 'add_empty' => __('option_select', null, 'table_list'))),
			'photo_url'        => new sfWidgetFormInputText(),
			'is_default' => new sfWidgetFormChoice(array('choices'=>$enables,'expanded'=>true)),
		));
		
		$this->setValidators(array(
			'candidate_id'        => new sfValidatorDoctrineChoice(array('model' => 'Candidates', 'query' => Doctrine_Query::create()->select('b.id, b.full_name name')->from('Candidates b')->where('b.is_enabled = 1 AND b.is_deleted = 0 AND (b.updated_at IS NULL OR b.updated_at >= b.created_at)'), 'required' => true),array('required'=> 'input candidate_id')),
			'photo_url'        => new sfValidatorString(array('max_length' => 255, 'required' => false)),
			'is_default' => new sfValidatorChoice(array('choices'=>array('0','1'))),
		));
		$this->setDefault('is_default', '0');
		parent::configure();

		
		/*
		 * Setting name of form
		 */
		$this->widgetSchema->setNameFormat('CandidatePhotos[%s]');
		$this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
	}
}
